import { defineStore } from 'pinia'
import { reqGetCategory } from '@/apis/home/index.ts'
import {GetAllCategoryResponseData,CategoryResponseData}  from "@/apis/home/type.ts"; 
const useCategoryStore = defineStore('category',  {

state: () => {
    return {
        //获取-全部分类推荐商品数据
        categoryList:[] as CategoryResponseData[]
    }
  },
  persist:true,
  actions:{
    //获取-全部分类(包含推荐商品)
    async getCategory (){
        const res:GetAllCategoryResponseData = await reqGetCategory()
        this.categoryList =res.result 
      }
    
  },
  getters:{
    topFiveItems(): CategoryResponseData[] {
        return this.categoryList.slice(0, 7); // 截取前五个元素
    }
  }
})
export default  useCategoryStore